package com.wangrui.client.form;

import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.DateItem;
import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.TimeItem;
import com.smartgwt.client.widgets.layout.HLayout;
import com.wangrui.client.GreetingService;
import com.wangrui.client.GreetingServiceAsync;

public class SipfLogForm extends Window{
	
	private DynamicForm checkSysForm ,patrolForm,dateForm,remarkForm;
	
	private HLayout buttonLayout;
	
	
	public SipfLogForm(){
		
		setWidth(800);
		setHeight(650);
		
		dateForm = new DynamicForm();
		dateForm.setNumCols(4);
		dateForm.setPadding(10);
		final DateItem OC_DATE = new DateItem("交易日期"); 
		final TextItem PERSON = new TextItem("记录人");
		dateForm.setFields(OC_DATE,PERSON);
		
		checkSysForm = new DynamicForm();
		checkSysForm.setIsGroup(true);
		checkSysForm.setNumCols(6);
		checkSysForm.setPadding(10);
		checkSysForm.setCellBorder(1);
		checkSysForm.setGroupTitle("核查类（8:45分前）");
		
		final TimeItem CLNHISSTART = new TimeItem("删除历史开始");
		final TimeItem CLNHISEND = new TimeItem("删除历史结束");
		final TimeItem CLNHISSUM = new TimeItem("删除历史耗时");
		
		final TimeItem PREHANDSTART = new TimeItem("预处理开始");
		final TimeItem PREHANDEND = new TimeItem("预处理结束");
		final TimeItem PREHANDSUM = new TimeItem("预处理耗时");
		
		final TimeItem INCRSTART = new TimeItem("增量生成开始");
		final TimeItem INCREND = new TimeItem("增量生成结束");
		final TimeItem INCRSUM = new TimeItem("增量生成耗时");
		
		final TimeItem INCREXPORTSTART = new TimeItem("增量导出开始");
		final TimeItem INCREXPORTEND = new TimeItem("增量导出结束");
		final TimeItem INCREXPORTSUM = new TimeItem("增量导出耗时"); 
		
		final TimeItem INCRCHKSTART = new TimeItem("增量导出开始");
		final TimeItem INCRCHKEND = new TimeItem("增量导出结束");
		final TimeItem INCRCHKSUM = new TimeItem("增量导出耗时");
		
		final TimeItem FULLSTART = new TimeItem("全量生成开始");
		final TimeItem FULLEND = new TimeItem("全量生成结束");
		final TimeItem FULLSUM = new TimeItem("全量生成耗时");
		
		final TimeItem FULLCHKSTART = new TimeItem("全量校验开始");
		final TimeItem FULLCHKEND = new TimeItem("全量校验结束");
		final TimeItem FULLCHKSUM = new TimeItem("全量校验耗时");
		
		final TimeItem FULLEXPORTSTART = new TimeItem("全量导出开始");
		final TimeItem FULLEXPORTEND = new TimeItem("全量导出结束");
		final TimeItem FULLEXPORTSUM = new TimeItem("全量导出耗时"); 
		
		final TimeItem FILESTART = new TimeItem("文件生成开始");
		final TimeItem FILEEND = new TimeItem("文件生成结束");
		final TimeItem FILESUM = new TimeItem("文件生成耗时");
		
		final TimeItem FILECHKSTART = new TimeItem("文件校验开始");
		final TimeItem FILECHKEND = new TimeItem("文件校验结束");
		final TimeItem FILECHKSUM = new TimeItem("文件校验耗时");
		
		final TimeItem FILEEXPORTSTART = new TimeItem("文件导出开始");
		final TimeItem FILEEXPORTEND = new TimeItem("文件导出结束");
		final TimeItem FILEEXPORTSUM = new TimeItem("文件导出耗时");
		
		final TimeItem FILEUPLOADSTART = new TimeItem("文件导出开始");
		final TimeItem FILEUPLOADEND = new TimeItem("文件导出结束");
		final TimeItem FILEUPLOADSUM = new TimeItem("文件导出耗时");
		
		checkSysForm.setFields(CLNHISSTART,CLNHISEND,CLNHISSUM,PREHANDSTART,PREHANDEND,PREHANDSUM,
				INCRSTART,INCREND,INCRSUM,INCREXPORTSTART,INCREXPORTEND,INCREXPORTSUM,INCRCHKSTART,INCRCHKEND,INCRCHKSUM,
				FULLSTART,FULLEND,FULLSUM,FULLCHKSTART,FULLCHKEND,FULLCHKSUM,FULLEXPORTSTART,FULLEXPORTEND,FULLEXPORTSUM,
				FILESTART,FILEEND,FILESUM,FILECHKSTART,FILECHKEND,FILECHKSUM,FILEEXPORTSTART,FILEEXPORTEND,FILEEXPORTSUM,
				FILEUPLOADSTART,FILEUPLOADEND,FILEUPLOADSUM);
		
		
		patrolForm = new DynamicForm();
		patrolForm.setIsGroup(true);
		patrolForm.setNumCols(4);
		patrolForm.setGroupTitle("日间巡查类");
		
		final RadioGroupItem COMPUTERSTATUS = new RadioGroupItem();   
		COMPUTERSTATUS.setTitle("系统状态");   
		COMPUTERSTATUS.setValueMap("正常", "不正常"); 
		
		final RadioGroupItem APPSTATUS = new RadioGroupItem();   
		APPSTATUS.setTitle("程序状态");   
		APPSTATUS.setValueMap("正常", "不正常"); 
		
		patrolForm.setFields(COMPUTERSTATUS,APPSTATUS);
		
		remarkForm = new DynamicForm();
		remarkForm.setWidth100();
		remarkForm.setHeight(100);
		remarkForm.setGroupTitle("数据核查问题及解决方法");
		remarkForm.setIsGroup(true);
		remarkForm.setPadding(5);
		final TextAreaItem REMARK = new TextAreaItem();   
		REMARK.setShowTitle(false);   
		REMARK.setLength(5000);   
		REMARK.setColSpan(2);   
		REMARK.setWidth("*");   
		REMARK.setHeight("*"); 
		
		final TextAreaItem STATUS = new TextAreaItem();   
		STATUS.setShowTitle(false);   
		STATUS.setLength(10);   
		STATUS.setColSpan(2);   
		STATUS.setWidth("*");   
		STATUS.setHeight("*"); 
		remarkForm.setFields(REMARK,STATUS);
		
		buttonLayout = new HLayout();
		buttonLayout.setPadding(10);
		buttonLayout.setAlign(Alignment.RIGHT);
		Button saveBt = new Button("保存");
		saveBt.setWidth(100);

	    saveBt.addClickHandler(new ClickHandler() {
		
		   
	
		public void onClick(ClickEvent event) {
			
			String testString = OC_DATE.getValueAsDate().toLocaleString().trim();
			
			GreetingServiceAsync addSipfLogService = GreetingService.Util.getInstance();
			
			AsyncCallback cb_addSipfLog = new AsyncCallback() {

		
				public void onFailure(Throwable caught) {}

				public void onSuccess(Object result) {

					Boolean ok = (Boolean)result;
					
					if(ok.booleanValue()){
						
						SC.say("日志保存成功");
						destroy();
					}else
						
						SC.say("日志保存失败");
					
				}
			};
			
			addSipfLogService.addSipfLog(OC_DATE.getValueAsDate().toLocaleString(), PERSON.getValueAsString(), STATUS.getValueAsString(), CLNHISSTART.getValueAsString(), CLNHISEND.getValueAsString(), CLNHISSUM.getValueAsString(), PREHANDSTART.getValueAsString(), PREHANDEND.getValueAsString(), PREHANDSUM.getValueAsString(), INCRSTART.getValueAsString(), INCREND.getValueAsString(), INCRSUM.getValueAsString(), INCREXPORTSTART.getValueAsString(), INCREXPORTEND.getValueAsString(), INCREXPORTSUM.getValueAsString(), INCRCHKSTART.getValueAsString(), INCRCHKEND.getValueAsString(), INCRCHKSUM.getValueAsString(), FULLSTART.getValueAsString(), FULLEND.getValueAsString(), FULLSUM.getValueAsString(), FULLCHKSTART.getValueAsString(), FULLCHKEND.getValueAsString(), FULLCHKSUM.getValueAsString(), FULLEXPORTSTART.getValueAsString(), FULLEXPORTEND.getValueAsString(), FULLEXPORTSUM.getValueAsString(), FILESTART.getValueAsString(), FILEEND.getValueAsString(), FILESUM.getAttribute(""), FILECHKSTART.getValueAsString(), FILECHKEND.getValueAsString(), FILECHKSUM.getValueAsString(), FILEEXPORTSTART.getValueAsString(), FILEEXPORTEND.getValueAsString(), FILEEXPORTSUM.getValueAsString(), FILEUPLOADSTART.getValueAsString(), FILEUPLOADEND.getValueAsString(), FILEUPLOADSUM.getValueAsString(), APPSTATUS.getValueAsString(), COMPUTERSTATUS.getValueAsString(), REMARK.getValueAsString(), cb_addSipfLog);
			
			System.out.println("测试得到的日期数据："+OC_DATE.getValueAsDate().toLocaleString());
			System.out.println("测试得到的输入内容："+PERSON.getValueAsString());
			System.out.println("测试打印radio的内容："+COMPUTERSTATUS.getValueAsString());
			
		}
	});
	    
	    
		
		
		buttonLayout.addMember(saveBt);
		
		setIsModal(true);
		setShowModalMask(true);
		centerInPage();
		addItem(dateForm);
		addItem(checkSysForm);
		addItem(patrolForm);
		addItem(remarkForm);
		addItem(buttonLayout);
		
	}

}
